home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / MPW / gzip 1.2.2 / cextras-1.0 / alloca.a next >
Encoding:
Text File  |  1993-07-08  |  1.3 KB  |  35 lines  |  [TEXT/MPS ]

  1. ;--------------------------------------------------------------------------------
  2. ;
  3. ;    alloca.a -- allocate memory using stack
  4. ;
  5. ;    Copyright (c) 1993, Anthony C. Ard
  6. ;
  7. ;    This program is free software; you can redistribute it and/or
  8. ;    modifiy it under the terms of the GNU General Public License
  9. ;    as published by the Free Software Foundation; either version 2
  10. ;    of the License, or (at your option) any later version.
  11. ;    
  12. ;    This program is distributed in the hope that it will be useful,
  13. ;    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;    GNU General Public License for more details.
  16. ;    
  17. ;    You should have received a copy of the GNU General Public License
  18. ;    along with this program; if not, write to the Free Software
  19. ;    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. ;
  21. ;--------------------------------------------------------------------------------
  22.  
  23. alloca    proc    export
  24.  
  25.     move.l    (sp)+,a0    ; pop return addr from top of stack
  26.     move.l    (sp)+,d0    ; pop size in bytes from top of stack
  27.     add.l    #3,d0        ; round size up to long word
  28.     and.l    #-4,d0        ; mask out lower two bits
  29.     sub.l    d0,sp        ; allocate by moving the stack pointer
  30.     move.l    sp,d0        ; pointer to the allocated block
  31.     add.l    #-4,sp        ; new top of stack
  32.     jmp    (a0)        ; don't use stack to return
  33.  
  34.     end
  35.